home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / gray image 2.1 / fractal_map.h < prev    next >
Text File  |  1995-05-03  |  3KB  |  90 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *                Grayscale Image
  6.  *                Generating Fractal Maps
  7.  * 
  8.  * Declaration of a class of recursive subdivision, or plasma, fractals,
  9.  * that generate self-similar images (with scaled noise).
  10.  *
  11.  * The fractal map is specified by its order, seeds, pixel depth, and
  12.  * the random-number generating algorithm. The order is the only necessary
  13.  * parameter, it specifies a square map (image) of dimension 2^order.
  14.  * Order should be at least two (and not too large). There are reasonable
  15.  * defaults for other parameters. Seeds are used to specify values 
  16.  * at the four corners of the map, map(0,0), map(2^order,0), 
  17.  * map(0,2^order) and map(2^order,2^order). Note, strictly speaking,
  18.  * the seeds except map(0,0) are actually outside of the image itself.
  19.  * The map isn't periodical, btw. The map points between the seeds
  20.  * are filled in as an average of the corresponding boundary points
  21.  * plus some random scaled noise. See "fractal_map.cc" for more
  22.  * details about the implementation.
  23.  *
  24.  * Usage examples:
  25.  *    IMAGE map1 = FractalMap(9);    // Use all the defaults
  26.  *    IMAGE map2 = FractalMap(9,Seeds(0,64,64,128));
  27.  *    class MyMap : public FractalMap
  28.  *    {
  29.  *      public:
  30.  *      int get_noise(const card scale) const { return your_random_number; }
  31.  *      MyMap(const card order) : FractalMap(order) {}
  32.  *    }
  33.  *    IMAGE map3 = MyMap(10);        // Play with your own random number gen
  34.  *
  35.  * One may also want to blur/sharpen the fractal map afterwards (to make
  36.  * it more appealing) by applying a corresponding filter, say, [1 1 1]
  37.  *
  38.  * Note, FractalMap is a LazyImage thing, that is, in
  39.  *    IMAGE map1 = FractalMap(9);
  40.  * map construction is done "inplace" and *no* image is copied.
  41.  *
  42.  * $Id: fractal_map.h,v 2.0 1995/03/16 17:39:58 oleg Exp oleg $
  43.  *
  44.  ************************************************************************
  45.  */
  46.  
  47. #ifndef __GNUC__
  48. #pragma once
  49. #endif
  50. #ifndef _fractal_map_h
  51. #define _fractal_map_h
  52.  
  53. #ifdef __GNUC__
  54. #pragma interface
  55. #endif
  56.  
  57. #include "image.h"
  58.  
  59. class FractalMap : public LazyImage
  60. {
  61. public:
  62.   class Seeds
  63.   {
  64.   public:
  65.     const GRAY s00, s10, s11, s01;
  66.  
  67.     Seeds(const GRAY seed) 
  68.       : s00(seed), s10(seed), s11(seed), s01(seed) {}
  69.     Seeds(const GRAY ul, const GRAY ll, const GRAY ur, const GRAY lr)
  70.       : s00(ul), s10(ll), s11(lr), s01(ur) {}
  71.   };
  72.   FractalMap(const card order, const Seeds& _seeds = Seeds(128),
  73.          const card bits_per_pixel=8);
  74.  
  75.                 // Get some noise with a dispersion 'scale'
  76.                 // (which is assumed to be a power of 2)
  77.                 // and average 0
  78.                 // Say, if scale=2 return either 0 or 1
  79.                 // if scale=128, return a random number
  80.                 // within [-64,63]
  81.   virtual int get_noise(const card scale) const;
  82. private:
  83.   Seeds seeds;
  84.   void fill_in(IMAGE& im) const;
  85. };
  86.  
  87. #endif
  88.  
  89.  
  90.